 package uk.co.mmscomputing.device.twain;
 
 import java.io.PrintStream;
 import uk.co.mmscomputing.device.scanner.Scanner;
 import uk.co.mmscomputing.device.scanner.ScannerIOException;
 import uk.co.mmscomputing.device.scanner.ScannerIOMetadata;
 import uk.co.mmscomputing.device.scanner.ScannerIOMetadata.Type;
 import uk.co.mmscomputing.device.scanner.ScannerListener;
 
 public class ADFTwainExample
   implements ScannerListener
 {
   static ADFTwainExample app;
   Scanner scanner;
   int transferCount = 0;
 
   public ADFTwainExample(String[] paramArrayOfString) throws ScannerIOException {
     this.scanner = Scanner.getDevice();
     this.scanner.addListener(this);
     this.scanner.acquire();
   }
 
   public void update(ScannerIOMetadata.Type paramType, ScannerIOMetadata paramScannerIOMetadata)
   {
     Object localObject;
     if (paramType.equals(ScannerIOMetadata.ACQUIRED)) {
       localObject = paramScannerIOMetadata.getImage();
       this.transferCount += 1;
       System.out.println("Got image number: " + this.transferCount);
     }
     else if (paramType.equals(ScannerIOMetadata.NEGOTIATE)) {
       localObject = ((TwainIOMetadata)paramScannerIOMetadata).getSource();
       String str = ((TwainSource)localObject).getProductName();
 
       ((TwainSource)localObject).setShowUI(false);
       try
       {
         ((TwainSource)localObject).getCapability(4385, 2).setCurrentValue(90.0D);
 
         ((TwainSource)localObject).getCapability(4098).setCurrentValue(true);
         ((TwainSource)localObject).getCapability(4103).setCurrentValue(true);
         ((TwainSource)localObject).getCapability(1).setCurrentValue(this.transferCount);
         this.transferCount = ((TwainSource)localObject).getCapability(1).intValue();
         System.out.println("set transferCount: " + this.transferCount);
       } catch (Exception localException2) {
         System.out.println("CAP_FEEDERENABLED/CAP_AUTOFEED/CAP_XFERCOUNT: " + localException2.getMessage());
       }
 
     }
     else if (paramType.equals(ScannerIOMetadata.STATECHANGE))
     {
       System.err.println(paramScannerIOMetadata.getStateStr() + " [" + paramScannerIOMetadata.getState() + "]");
 
       if ((paramScannerIOMetadata.getLastState() == 4) && (paramScannerIOMetadata.getState() == 3)) {
         if (this.transferCount < 5)
           try {
             this.scanner.acquire();
           } catch (Exception localException1) {
             System.err.println(localException1);
           }
         else
           System.exit(0);
       }
     }
     else if (paramType.equals(ScannerIOMetadata.EXCEPTION)) {
       paramScannerIOMetadata.getException().printStackTrace();
     }
   }
 
   public static void main(String[] paramArrayOfString) {
     try {
       app = new ADFTwainExample(paramArrayOfString);
     } catch (Exception localException) {
       localException.printStackTrace();
     }
   }
 }

